<template>
    <el-dialog v-dialogDrag title="档案归档" :visible="editShow" width="30%" @close="dialogClose"
      :close-on-click-modal="false">
      <el-form ref="editForm" :model="formFileds" :rules="rules" label-width="auto">
        <el-form-item label="归档位置：" prop="location">
          <el-input type="text" v-model="formFileds.location"></el-input>
        </el-form-item>
        <el-form-item label="印章：" prop="seal">
          <el-radio-group v-model="formFileds.seal">
            <el-radio label='true'>有</el-radio>
            <el-radio label='false'>无</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注：" prop="备注">
          <el-input type="text" v-model="formFileds.remark"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm()" class="pull-right margin-l-25">确定
          </el-button>
          <el-button @click="dialogClose" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
</template>

<script>
import { getDocument } from '@/api/evaluation/document';
export default {
  name:'Document',
  //接受父组件
  props: {
    editShow: {
      type: Boolean,
    },
    record: {
      type: Object
    }
  },

  data () {
    return {
      formFileds: {},
      rules: {
        location: [
          {
            // required: true,
            message: "请输入归档位置",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    dialogClose () {
      this.$emit("dialogClose");
    },
    submitForm () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          if(this.formFileds.seal=='true'){
            this.formFileds.seal=true
          }else{
            this.formFileds.seal=false
          }
          getDocument(this.formFileds).then((res)=>{
            this.$message.success('保存成功！')
            this.$emit('getList')
            this.$emit('dialogClose')
          })
        } else {
          return;
        }
      });
    },
  },
  mounted () {
    this.formFileds = Object.assign({}, this.record)
    if(this.formFileds.seal==true){
      this.formFileds.seal='true'
    }else{
      this.formFileds.seal='false'
    }
  }
};
</script>

<style lang="less" scoped>
.el-form{
  padding: 0 10% 0 5%;
}
</style>
